class_name CustomPatternMatrix
extends Resource

## 模式（√表示这个必须有，×表示必须没有，○表示可有可无，多行需要换行，必须是一个矩形）
@export_multiline var pattern:String = "√×○"
var inited:bool = false
var pattern_matrix:Array[Array] = []

func get_shape() -> Vector2i:
	if not inited:
		init_matrix()
	return Vector2i(pattern_matrix.size(),pattern_matrix[0].size())
func init_matrix():
	inited = true
	for str in pattern.split("\n"):
		var arr = []
		pattern_matrix.append(arr)
		for s in str:
			arr.append(s)
func check_pattern(matrix:Array[Array],check_func:Callable = func(x):return x != null) -> bool:
	if not inited:
		init_matrix()
	if pattern_matrix.size() != matrix.size():
		return false
	for i in range(pattern_matrix.size()):
		if pattern_matrix[i].size() != matrix[i].size():
			return false
	for row in range(pattern_matrix.size()):
		for col in range(pattern_matrix[row].size()):
			var flag = pattern_matrix[row][col]
			if flag == "√":
				if not check_func.call(matrix[row][col]):
					return false
			elif flag == "×":
				if check_func.call(matrix[row][col]):
					return false
	return true
